package com.jiahao.material.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiahao.material.entity.Customer;
import com.jiahao.material.entity.Supplier;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

public interface CustomerMapepr extends BaseMapper<Customer> {

    @Results(id = "customerId",value = {
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "name",property = "name"),
            @Result(column = "contact",property = "contact"),
            @Result(column = "phone",property = "phone"),
            @Result(column = "email",property = "email"),
            @Result(column = "address",property = "address"),
            @Result(column = "remarks",property = "remarks"),
            @Result(column = "createTime",property = "createTime"),
            @Result(column = "updateTime",property = "updateTime"),
            @Result(column = "status",property = "status"),
            @Result(column = "id",property = "deliverys",many = @Many(select = "com.jiahao.material.mapper.DeliveryMapper.getByCid"))
    })
    @Select({
            "<script>",
            "select * from customer ",
            "<where>",
            "<if test='map.name!=null and map.name !=\"\"'>and name like concat(concat('%',#{map.name},'%'))</if>",
            "<if test='map.contact!=null and map.contact !=\"\"'>and contact like concat(concat('%',#{map.contact},'%'))</if>",
            "<if test='map.status!=null and map.status !=\"\"'>and status=#{map.status}</if>",
            "</where>",
            "</script>"
    })
    public IPage<Customer> getByPage(Page<Customer> page, Map<String,Object> map);
}
